package com.crocodile.game17.common;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public static <T> R<T> exceptionHandle(Exception e) throws InterruptedException {
        if(e instanceof AppException){
            AppException app = (AppException) e;
            return R.error(app.getMsg(),app.getStatus());
        }

        return R.error(e.toString(),500);
    }
}
